package stringExertises;

/**
 * @author: bamboo_shoot
 * @date: 20/2/3 23:26
 * @description: 需求：定义一个方法，把数组{1,2,3}按照指定个格式拼接成一个字符串。格式参照如下：[word1#word2#word3]。这里是另一种做法
 */
public class ConcatenatedStringSecond {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3};
        String str = arrayString(arr);
        System.out.println(str);
    }

    private static String arrayString(int[] arr) {
        String s = "[";
        for (int i = 0; i < arr.length; i++) {
            if (i < arr.length - 1) {
                s = s + arr[i] + "#";
            }
            if (i==arr.length-1) {
                s =s+ arr[i] + "]";
            }
        }
        return s;
    }
}
